
require(['./config'], () => {
  require(['template',  'request','jquery', 'header', 'footer', 'popper', 'bootstrap','nav'],(template, req)=>{
    class Search{
      constructor(){
        this.load()
        .then(()=>{
          this.hello()
        })
      }
      load(){
        return new Promise(resolve=>{
          resolve()
        })
      }
      hello(){
        //读取cookie里面的值
        const cookie = window.location.href
        //cookie的值
        // 
        let value = cookie.split('?')[1].split('=')[1]
        value =  decodeURIComponent(value)
        //拿到所有的商品lis
        console.log(value)
        req.getsProductData()
        .then(res => {
          let you = res.filter(item=>{
            //这个要用到字符串比较 indexOf()
              if(item.name.indexOf(value) !== -1)
              return item
          })
          $('.cb_search_v').text(`${you.length}`)
          const html = template('productLists', {
            prodlist: you
          })
          $('#prouctsContent').html(html);

        })

      }
    }

    return new Search()
  })
})